﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApC3DAppearanceSet
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApC3DAppearanceSet
{
  private Dictionary<ITxDisplayableObject, List<CApC3DAppearance>> m_appearances = new Dictionary<ITxDisplayableObject, List<CApC3DAppearance>>();

  public void AddAppearance(ITxDisplayableObject obj, TxSnapshot snapshot)
  {
    if (!CApC3DUtils.IsObjOfAppearanceType((ITxObject) obj))
      return;
    if (!this.m_appearances.ContainsKey(obj))
      this.m_appearances.Add(obj, new List<CApC3DAppearance>());
    CApC3DAppearance equivalentAppearance = this.GetEquivalentAppearance(obj);
    if (equivalentAppearance == null)
    {
      List<CApC3DAppearance> appearance = this.m_appearances[obj];
      string viewId = appearance.Count.ToString();
      CApC3DAppearance capC3Dappearance = new CApC3DAppearance((ITxObject) obj, viewId, snapshot);
      appearance.Add(capC3Dappearance);
    }
    else
      equivalentAppearance.AddSnapshot(snapshot);
  }

  public void Remove(ITxDisplayableObject obj) => this.m_appearances.Remove(obj);

  public ArrayList GetAllAppearances()
  {
    ArrayList allAppearances = new ArrayList();
    foreach (KeyValuePair<ITxDisplayableObject, List<CApC3DAppearance>> appearance in this.m_appearances)
    {
      foreach (CApC3DAppearance capC3Dappearance in appearance.Value)
        allAppearances.Add((object) capC3Dappearance);
    }
    return allAppearances;
  }

  public CApC3DAppearance GetAppearance(ITxDisplayableObject obj, string viewId)
  {
    if (obj != null && CApC3DUtils.IsObjOfAppearanceType((ITxObject) obj))
    {
      foreach (CApC3DAppearance appearance in this.m_appearances[obj])
      {
        if (appearance.GetData().ViewId == viewId)
          return appearance;
      }
    }
    return (CApC3DAppearance) null;
  }

  private CApC3DAppearance GetEquivalentAppearance(ITxDisplayableObject obj)
  {
    if (obj != null && CApC3DUtils.IsObjOfAppearanceType((ITxObject) obj))
    {
      foreach (CApC3DAppearance equivalentAppearance in this.m_appearances[obj])
      {
        if (equivalentAppearance.IsEquivalent((ITxObject) obj))
          return equivalentAppearance;
      }
    }
    return (CApC3DAppearance) null;
  }
}
